﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TriganleTests.Question;

namespace TriganleTests.Answer
{
    public class Edward : ITriangle
    {
        public int InTriangle(MyPoint A, MyPoint B, MyPoint C, MyPoint test)
        {
            //(ad＋be＋cf－af－bc－de)/2
            double S = ((A.X * B.Y) + (A.Y * C.X) + (B.X * C.Y) - (A.X * C.Y) - (A.Y * B.X) - (B.Y * C.X));

            //Part A
            MyPoint temp = A;
            A = test;
            double S1 = ((A.X * B.Y) + (A.Y * C.X) + (B.X * C.Y) - (A.X * C.Y) - (A.Y * B.X) - (B.Y * C.X));
            A = temp;

            //Part B
            temp = B;
            B = test;
            double S2 = ((A.X * B.Y) + (A.Y * C.X) + (B.X * C.Y) - (A.X * C.Y) - (A.Y * B.X) - (B.Y * C.X));
            B = temp;

            //Part C
            temp = C;
            C = test;
            double S3 = ((A.X * B.Y) + (A.Y * C.X) + (B.X * C.Y) - (A.X * C.Y) - (A.Y * B.X) - (B.Y * C.X));
            C = temp;

            if (S == S1 + S2 + S3) return 1;


            return -1;
        }
    }
}
